package com.itheima.controller;

import com.itheima.health.entity.Result;
import com.itheima.health.service.OrderSettingService;
import com.itheima.health.utils.poi.POIUtils;
import io.swagger.annotations.Api;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@Api(tags = "预约管理开发")
@RequestMapping("ordersetting")
public class OrderSettingController {

    @Reference
    private OrderSettingService orderSettingService;

    //xlsx表格上传
    @PostMapping("importOrderSettings")
    public Result importOrderSettings(@RequestParam("excelFile") MultipartFile file){
        //将上传文件存放到集合中
        List<String[]> OrderSettingList = POIUtils.readExcel(file);
        //将xlsx表格上传到数据库
        orderSettingService.importOrderSettings(OrderSettingList);
        //成功返回true ,失败由全局异常返回
        return new Result(true);
    }

    //查询当前日期的预约数据
    @GetMapping("findSettingData/{year}/{month}")
    public Result findSettingData(@PathVariable("year") int year, @PathVariable("month") int month) {
        return new Result(orderSettingService.findSettingData(year, month));
    }



    //更新当前日期的最大预约人数
    @PutMapping("updateNumberByOrderdate/{number}/{settingDay}")
    public Result updateNumberByOrderdate(@PathVariable("number") int number, @PathVariable("settingDay") String settingDay) {
        return new Result(orderSettingService.updateNumberByOrderdate(number,settingDay));
    }

}
